Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EventEmitter to XCM executor. #7234

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jpserrat
Copy link
Contributor

@jpserrat jpserrat commented Jan 18, 2025

Closes #6851

@franciscoaguirre I added the EventEmitter trait to the config. I have two questions on this:

  1. I created a new file to put the trait in, is this ok?
  2. For EventEmitter trait I've created a sent event function instead a generic one that emits any event, do you prefer a generic one?

@jpserrat jpserrat requested a review from a team as a code owner January 18, 2025 14:05
@paritytech-review-bot paritytech-review-bot bot requested a review from a team January 18, 2025 14:06
@@ -427,9 +428,20 @@ impl<Config: config::Config> XcmExecutor<Config> {
reason = ?reason,
"Sending msg",
);
let (ticket, fee) = validate_send::<Config::XcmSender>(dest, msg)?;
let (ticket, fee) = validate_send::<Config::XcmSender>(dest.clone(), msg.clone())?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thinking out loud, do we really want to log/use msg.clone here?
My concern is that some Config::XcmSender / SendXcm implementations might modify the msg, such as WithUniqueTopic. This could lead to confusion, as the msg in the event might differ from the one actually sent (or received on the other side).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely don't include full message in event, see my comment in the trait definition


use xcm::latest::prelude::*;

pub trait EventEmitter {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add some documentation here at least

use xcm::latest::prelude::*;

pub trait EventEmitter {
fn emit_sent_event(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The emit_sent_event function, with Self::deposit_event(Event::Sent, makes it a single-purpose solution.

I would prefer a more general approach. For example, there’s a very relevant issue where we want/need to emit a failure event from ProcessXcmMessage.

If we could address this issue using an EventEmitter, that would be fantastic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one option is this trait to have multiple functions, each specific to xcm-executor events

fn emit_sent_event is one
fn emit_process_event is another
etc

use xcm::latest::prelude::*;

pub trait EventEmitter {
fn emit_sent_event(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one option is this trait to have multiple functions, each specific to xcm-executor events

fn emit_sent_event is one
fn emit_process_event is another
etc

fn emit_sent_event(
origin: Location,
destination: Location,
message: Xcm<()>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
message: Xcm<()>,

definitely cannot include full message in Events, on chain storage should be kept to a minimum

providing the message_id: XcmHash should be enough

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove this from the other events? In pallet xcm we are emitting this sent event with the message.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, do not change any existing events, we don't know how indexers or exchanges exactly depend on them and we risk breaking something

@@ -46,6 +46,7 @@ mod assets;
pub use assets::AssetsInHolding;
mod config;
pub use config::Config;
use crate::traits::EventEmitter;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to the use traits::{... above

@@ -427,9 +428,20 @@ impl<Config: config::Config> XcmExecutor<Config> {
reason = ?reason,
"Sending msg",
);
let (ticket, fee) = validate_send::<Config::XcmSender>(dest, msg)?;
let (ticket, fee) = validate_send::<Config::XcmSender>(dest.clone(), msg.clone())?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely don't include full message in event, see my comment in the trait definition

Config::XcmSender::deliver(ticket).map_err(Into::into)
let message_id = match Config::XcmSender::deliver(ticket) {
Ok(message_id) => message_id,
Err(e) => return Err(e.into()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should emit event for error too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we are going to send a event for the process failure, should we just send the process failure event or send both event on the send failure and process failure?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally, the process failure event would clearly describe the failure as a send failure

if not possible/easy, an extra explicit send failure event is also ok

message: Xcm<()>,
message_id: XcmHash,
) {
Self::deposit_event(Event::Sent { origin, destination, message, message_id });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would not reuse Event::Sent which is used by pallet_xcm::send()

Suggested change
Self::deposit_event(Event::Sent { origin, destination, message, message_id });
Self::deposit_event(Event::XcmExecutorSent { origin, destination, message_id });

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you not reuse it? Are they really that different?
If they're just one, apps can just subscribe to one event and know all cross-chain messages from that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, on second thought we could reuse, I am still not sure about including the full message in the event though, some messages could be quite big

@franciscoaguirre franciscoaguirre added the T6-XCM This PR/Issue is related to XCM. label Jan 28, 2025
@franciscoaguirre franciscoaguirre self-assigned this Jan 28, 2025
@acatangiu
Copy link
Contributor

@jpserrat do you plan on finishing this PR or should we take over?

@jpserrat
Copy link
Contributor Author

@acatangiu Sorry for the delay on this. I'm going to finish.

@raymondkfcheung
Copy link

If #7200 is merged before your PR, you may need add the new EventEmitter on the XcmTestConfig.

@paritytech-review-bot paritytech-review-bot bot requested a review from a team February 12, 2025 21:20
@@ -813,6 +831,7 @@ impl<Config: config::Config> XcmExecutor<Config> {
self.process_instruction(instr)
});
if let Err(e) = inst_res {
Config::XcmEventEmitter::emit_process_failure_event(self.original_origin.clone(), e.clone());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this line, emit_process_failure_event, below, the tracing. Then we can see the trace, even it fails to emit.

Comment on lines +437 to +440
/// A XCM message failed to be sent.
SentFailed { origin: Location, destination: Location, error: SendError },
/// Process XCM message failed.
ProcessXcmError { origin: Location, error: XcmError },

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two new events should include, message_id, for better message tracking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For these ones when the event is emitted we don't have the message id. This was something that I was in doubt when creating this two events. Do you have any suggestion on what we can add to these events?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is possible to retrieve message_id from SetTopic or properties.message_id?

Comment on lines +414 to +427
fn emit_sent_failure_event(
origin: Location,
destination: Location,
error: SendError,
) {
Self::deposit_event(Event::SentFailed { origin, destination, error });
}

fn emit_process_failure_event(
origin: Location,
error: XcmError,
) {
Self::deposit_event(Event::ProcessXcmError { origin, error });
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two functions are not tested.

Comment on lines +22 to +24
origin: Location,
destination: Location,
message_id: XcmHash,
Copy link

@raymondkfcheung raymondkfcheung Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use references like origin: &Location, destination: &Location, message_id: &XcmHash? Similar to other two functions.

Also, please include the message.

Comment on lines +27 to +35
fn emit_sent_failure_event(
origin: Location,
destination: Location,
error: SendError,
);
fn emit_process_failure_event(
origin: Location,
error: XcmError
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include message_id.

@raymondkfcheung raymondkfcheung self-assigned this Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T6-XCM This PR/Issue is related to XCM.
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Add "Sent" event when a message is sent via execute
5 participants